```html
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>深入解析MyBatis插件机制 | 技术小馆</title>
    <link href="https://cdn.staticfile.org/font-awesome/6.4.0/css/all.min.css" rel="stylesheet">
    <link href="https://cdn.staticfile.org/tailwindcss/2.2.19/tailwind.min.css" rel="stylesheet">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.min.js"></script>
    <style>
        body {
            font-family: 'Noto Sans SC', Tahoma, Arial, Roboto, "Droid Sans", "Helvetica Neue", "Droid Sans Fallback", "Heiti SC", "Hiragino Sans GB", Simsun, sans-serif;
            line-height: 1.6;
            color: #333;
        }
        .hero {
            background: linear-gradient(135deg, #6e8efb 0%, #a777e3 100%);
        }
        h1, h2, h3, h4 {
            font-family: 'Noto Serif SC', serif;
            font-weight: 600;
        }
        .code-block {
            background: #2d3748;
            border-left: 4px solid #4299e1;
        }
        .plugin-flow {
            position: relative;
        }
        .plugin-flow:before {
            content: '';
            position: absolute;
            left: 20px;
            top: 0;
            bottom: 0;
            width: 2px;
            background: linear-gradient(to bottom, #4299e1, #a777e3);
        }
        .plugin-step {
            position: relative;
            padding-left: 50px;
        }
        .plugin-step:before {
            content: '';
            position: absolute;
            left: 12px;
            top: 8px;
            width: 16px;
            height: 16px;
            border-radius: 50%;
            background: #4299e1;
            border: 3px solid white;
            box-shadow: 0 0 0 2px #4299e1;
        }
        .card:hover {
            transform: translateY(-5px);
            box-shadow: 0 10px 25px rgba(0, 0, 0, 0.1);
        }
        .highlight {
            position: relative;
        }
        .highlight:after {
            content: '';
            position: absolute;
            left: 0;
            bottom: 2px;
            width: 100%;
            height: 8px;
            background: rgba(167, 119, 227, 0.3);
            z-index: -1;
            transition: all 0.3s ease;
        }
        .highlight:hover:after {
            height: 14px;
            background: rgba(167, 119, 227, 0.5);
        }
    </style>
</head>
<body class="bg-gray-50">
    <!-- Hero Section -->
    <section class="hero text-white py-20 md:py-32 px-4 md:px-0">
        <div class="container mx-auto max-w-5xl flex flex-col items-center text-center">
            <div class="mb-6 inline-flex items-center px-4 py-2 bg-white bg-opacity-20 rounded-full">
                <i class="fas fa-code mr-2"></i>
                <span class="text-sm font-medium">MyBatis深入解析</span>
            </div>
            <h1 class="text-4xl md:text-5xl font-bold mb-6 leading-tight">探索MyBatis<span class="highlight">插件机制</span>的奥秘</h1>
            <p class="text-xl md:text-2xl opacity-90 max-w-3xl mb-8">通过反射与代理技术实现SQL执行过程的无缝增强</p>
            <div class="flex space-x-4">
                <a href="#mechanism" class="px-6 py-3 bg-white text-indigo-600 font-medium rounded-lg hover:bg-opacity-90 transition-all">
                    <i class="fas fa-play-circle mr-2"></i>工作机制
                </a>
                <a href="#example" class="px-6 py-3 border border-white text-white font-medium rounded-lg hover:bg-white hover:bg-opacity-10 transition-all">
                    <i class="fas fa-code mr-2"></i>实战示例
                </a>
            </div>
        </div>
    </section>

    <!-- Main Content -->
    <div class="container mx-auto max-w-5xl px-4 md:px-0 py-12">
        <!-- Intro -->
        <section class="mb-16">
            <p class="text-xl text-gray-700 leading-relaxed mb-8">
                在MyBatis框架中，插件机制允许开发者在SQL执行的过程中插入自定义的行为，从而实现对执行过程的增强和扩展。通过插件机制，开发者可以在不修改MyBatis核心代码的情况下，实现日志记录、性能监控、权限控制等功能。
            </p>
            
            <div class="bg-blue-50 border-l-4 border-blue-500 p-6 rounded-r-lg mb-8">
                <div class="flex">
                    <div class="flex-shrink-0 text-blue-500">
                        <i class="fas fa-lightbulb text-2xl"></i>
                    </div>
                    <div class="ml-3">
                        <h3 class="text-lg font-medium text-blue-800">核心价值</h3>
                        <div class="mt-2 text-blue-700">
                            <p>MyBatis插件机制基于<strong>开闭原则</strong>，允许开发者扩展框架功能而无需修改源码，是框架可扩展性的重要体现。</p>
                        </div>
                    </div>
                </div>
            </div>
        </section>

        <!-- Section 1 -->
        <section id="mechanism" class="mb-16">
            <h2 class="text-3xl font-bold mb-6 flex items-center">
                <span class="bg-indigo-100 text-indigo-800 w-10 h-10 rounded-full flex items-center justify-center mr-4">1</span>
                <span>插件机制的基础</span>
            </h2>
            <p class="text-gray-700 mb-6">
                MyBatis的插件机制基于Java的反射和代理技术，允许开发者在SQL执行的过程中对特定的接口进行拦截，并在执行前后添加自定义的行为。MyBatis通过插件接口(<code>Interceptor</code>)和插件注册机制来支持这一特性。
            </p>
            
            <div class="code-block rounded-lg overflow-hidden mb-8">
                <div class="flex items-center px-4 py-2 bg-gray-700 text-gray-200">
                    <div class="flex space-x-2 mr-4">
                        <span class="w-3 h-3 rounded-full bg-red-500"></span>
                        <span class="w-3 h-3 rounded-full bg-yellow-500"></span>
                        <span class="w-3 h-3 rounded-full bg-green-500"></span>
                    </div>
                    <span class="text-sm">Interceptor.java</span>
                </div>
                <pre class="p-4 text-gray-100 overflow-x-auto"><code>public interface Interceptor {
    Object intercept(Invocation invocation) throws Throwable;  // 拦截执行
    Object plugin(Object target);  // 为目标对象创建代理
    void setProperties(Properties properties);  // 设置插件的属性
}</code></pre>
            </div>
            
            <div class="grid md:grid-cols-2 gap-6 mb-8">
                <div class="bg-white p-6 rounded-xl shadow-md border border-gray-100">
                    <div class="text-indigo-600 mb-3">
                        <i class="fas fa-project-diagram text-2xl"></i>
                    </div>
                    <h3 class="font-bold text-lg mb-2">代理模式</h3>
                    <p class="text-gray-600">MyBatis使用代理模式将插件包装在目标对象上。当MyBatis的某个对象执行时，插件会拦截并执行自定义行为。</p>
                </div>
                <div class="bg-white p-6 rounded-xl shadow-md border border-gray-100">
                    <div class="text-pink-600 mb-3">
                        <i class="fas fa-bullseye text-2xl"></i>
                    </div>
                    <h3 class="font-bold text-lg mb-2">拦截目标</h3>
                    <p class="text-gray-600">可以拦截Executor、StatementHandler、ParameterHandler和ResultSetHandler四大核心组件的方法。</p>
                </div>
            </div>
        </section>

        <!-- Section 2 -->
        <section class="mb-16">
            <h2 class="text-3xl font-bold mb-6 flex items-center">
                <span class="bg-indigo-100 text-indigo-800 w-10 h-10 rounded-full flex items-center justify-center mr-4">2</span>
                <span>插件注册机制</span>
            </h2>
            <p class="text-gray-700 mb-6">
                MyBatis允许用户在<code>mybatis-config.xml</code>配置文件中注册插件。插件注册的过程实际上是将插件的类名称配置在MyBatis的<code>Configuration</code>对象中，并通过反射实例化插件类。
            </p>
            
            <div class="flex flex-col md:flex-row gap-6 mb-8">
                <div class="flex-1">
                    <div class="code-block rounded-lg overflow-hidden">
                        <div class="flex items-center px-4 py-2 bg-gray-700 text-gray-200">
                            <div class="flex space-x-2 mr-4">
                                <span class="w-3 h-3 rounded-full bg-red-500"></span>
                                <span class="w-3 h-3 rounded-full bg-yellow-500"></span>
                                <span class="w-3 h-3 rounded-full bg-green-500"></span>
                            </div>
                            <span class="text-sm">mybatis-config.xml</span>
                        </div>
                        <pre class="p-4 text-gray-100 overflow-x-auto"><code>&lt;plugins&gt;
    &lt;plugin interceptor="com.example.MyPlugin"&gt;
        &lt;property name="someProperty" value="someValue"/&gt;
    &lt;/plugin&gt;
&lt;/plugins&gt;</code></pre>
                    </div>
                </div>
                <div class="flex-1">
                    <div class="code-block rounded-lg overflow-hidden">
                        <div class="flex items-center px-4 py-2 bg-gray-700 text-gray-200">
                            <div class="flex space-x-2 mr-4">
                                <span class="w-3 h-3 rounded-full bg-red-500"></span>
                                <span class="w-3 h-3 rounded-full bg-yellow-500"></span>
                                <span class="w-3 h-3 rounded-full bg-green-500"></span>
                            </div>
                            <span class="text-sm">Configuration.java</span>
                        </div>
                        <pre class="p-4 text-gray-100 overflow-x-auto"><code>public class Configuration {
    private List&lt;Interceptor&gt; interceptors = new ArrayList&lt;&gt;();

    public void addInterceptor(Interceptor interceptor) {
        interceptors.add(interceptor);  // 注册插件
    }
    
    public List&lt;Interceptor&gt; getInterceptors() {
        return interceptors;
    }
}</code></pre>
                    </div>
                </div>
            </div>
            
            <div class="bg-yellow-50 border-l-4 border-yellow-500 p-6 rounded-r-lg">
                <div class="flex">
                    <div class="flex-shrink-0 text-yellow-500">
                        <i class="fas fa-exclamation-triangle text-2xl"></i>
                    </div>
                    <div class="ml-3">
                        <h3 class="text-lg font-medium text-yellow-800">注意事项</h3>
                        <div class="mt-2 text-yellow-700">
                            <p>插件的注册顺序决定了它们的执行顺序。先注册的插件会先执行，后注册的插件会后执行，形成一个插件链。</p>
                        </div>
                    </div>
                </div>
            </div>
        </section>

        <!-- Section 3 -->
        <section class="mb-16">
            <h2 class="text-3xl font-bold mb-6 flex items-center">
                <span class="bg-indigo-100 text-indigo-800 w-10 h-10 rounded-full flex items-center justify-center mr-4">3</span>
                <span>插件的工作原理</span>
            </h2>
            
            <div class="plugin-flow mb-8">
                <div class="plugin-step mb-8">
                    <div class="bg-white p-6 rounded-xl shadow-md border border-gray-100">
                        <h3 class="font-bold text-lg mb-2 text-indigo-700">1. 创建目标对象</h3>
                        <p class="text-gray-600">MyBatis首先创建目标对象（如Executor、StatementHandler等）。</p>
                    </div>
                </div>
                
                <div class="plugin-step mb-8">
                    <div class="bg-white p-6 rounded-xl shadow-md border border-gray-100">
                        <h3 class="font-bold text-lg mb-2 text-indigo-700">2. 生成代理对象</h3>
                        <p class="text-gray-600">插件通过<code>plugin()</code>方法为目标对象生成代理对象。</p>
                        <div class="code-block rounded-lg overflow-hidden mt-4">
                            <pre class="p-4 text-gray-100 overflow-x-auto text-sm"><code>public Object plugin(Object target) {
    return Proxy.newProxyInstance(target.getClass().getClassLoader(),
                                target.getClass().getInterfaces(),
                                new Plugin(target, this));
}</code></pre>
                        </div>
                    </div>
                </div>
                
                <div class="plugin-step mb-8">
                    <div class="bg-white p-6 rounded-xl shadow-md border border-gray-100">
                        <h3 class="font-bold text-lg mb-2 text-indigo-700">3. 方法拦截</h3>
                        <p class="text-gray-600">在执行目标方法时，代理对象会调用<code>intercept()</code>方法。</p>
                    </div>
                </div>
                
                <div class="plugin-step mb-8">
                    <div class="bg-white p-6 rounded-xl shadow-md border border-gray-100">
                        <h3 class="font-bold text-lg mb-2 text-indigo-700">4. 执行目标方法</h3>
                        <p class="text-gray-600">插件在<code>intercept()</code>中执行自定义逻辑，然后通过<code>Invocation.proceed()</code>调用目标方法。</p>
                    </div>
                </div>
                
                <div class="plugin-step">
                    <div class="bg-white p-6 rounded-xl shadow-md border border-gray-100">
                        <h3 class="font-bold text-lg mb-2 text-indigo-700">5. 返回结果</h3>
                        <p class="text-gray-600">插件可以在目标方法执行前或后修改方法的参数或返回值，最终将结果返回给MyBatis。</p>
                    </div>
                </div>
            </div>
            
            <div class="mb-8">
                <div class="mermaid">
                    sequenceDiagram
                        participant Client
                        participant Proxy
                        participant Interceptor
                        participant Target
                        
                        Client->>Proxy: 调用方法
                        Proxy->>Interceptor: intercept()
                        Interceptor->>Target: proceed()
                        Target-->>Interceptor: 返回结果
                        Interceptor-->>Proxy: 返回结果
                        Proxy-->>Client: 返回结果
                </div>
            </div>
        </section>

        <!-- Section 4 -->
        <section class="mb-16">
            <h2 class="text-3xl font-bold mb-6 flex items-center">
                <span class="bg-indigo-100 text-indigo-800 w-10 h-10 rounded-full flex items-center justify-center mr-4">4</span>
                <span>Invocation对象</span>
            </h2>
            <p class="text-gray-700 mb-6">
                <code>Invocation</code>对象是插件机制中的一个核心概念，它封装了目标方法的调用信息，并传递给插件进行拦截。通过<code>Invocation</code>对象，插件能够获取目标方法的参数、方法名以及方法调用的结果。
            </p>
            
            <div class="grid md:grid-cols-2 gap-6">
                <div>
                    <div class="code-block rounded-lg overflow-hidden">
                        <div class="flex items-center px-4 py-2 bg-gray-700 text-gray-200">
                            <div class="flex space-x-2 mr-4">
                                <span class="w-3 h-3 rounded-full bg-red-500"></span>
                                <span class="w-3 h-3 rounded-full bg-yellow-500"></span>
                                <span class="w-3 h-3 rounded-full bg-green-500"></span>
                            </div>
                            <span class="text-sm">Invocation.java</span>
                        </div>
                        <pre class="p-4 text-gray-100 overflow-x-auto"><code>public class Invocation {
    private Object target;  // 目标对象
    private Method method;  // 目标方法
    private Object[] args;  // 方法参数

    public Object proceed() throws Throwable {
        return method.invoke(target, args);
    }
}</code></pre>
                    </div>
                </div>
                <div>
                    <div class="bg-white p-6 rounded-xl shadow-md border border-gray-100 h-full">
                        <div class="flex items-center mb-4">
                            <div class="bg-indigo-100 text-indigo-800 p-3 rounded-lg mr-4">
                                <i class="fas fa-cube text-xl"></i>
                            </div>
                            <div>
                                <h3 class="font-bold text-lg">关键组成</h3>
                            </div>
                        </div>
                        <ul class="space-y-3 text-gray-600">
                            <li class="flex items-start">
                                <i class="fas fa-check-circle text-indigo-500 mt-1 mr-2"></i>
                                <span><strong>target</strong> - 被代理的目标对象</span>
                            </li>
                            <li class="flex items-start">
                                <i class="fas fa-check-circle text-indigo-500 mt-1 mr-2"></i>
                                <span><strong>method</strong> - 被拦截的目标方法</span>
                            </li>
                            <li class="flex items-start">
                                <i class="fas fa-check-circle text-indigo-500 mt-1 mr-2"></i>
                                <span><strong>args</strong> - 方法调用的参数数组</span>
                            </li>
                        </ul>
                    </div>
                </div>
            </div>
        </section>

        <!-- Section 5 -->
        <section id="example" class="mb-16">
            <h2 class="text-3xl font-bold mb-6 flex items-center">
                <span class="bg-indigo-100 text-indigo-800 w-10 h-10 rounded-full flex items-center justify-center mr-4">5</span>
                <span>插件示例：SQL执行时间监控</span>
            </h2>
            
            <div class="code-block rounded-lg overflow-hidden mb-8">
                <div class="flex items-center px-4 py-2 bg-gray-700 text-gray-200">
                    <div class="flex space-x-2 mr-4">
                        <span class="w-3 h-3 rounded-full bg-red-500"></span>
                        <span class="w-3 h-3 rounded-full bg-yellow-500"></span>
                        <span class="w-3 h-3 rounded-full bg-green-500"></span>
                    </div>
                    <span class="text-sm">MyPlugin.java</span>
                </div>
                <pre class="p-4 text-gray-100 overflow-x-auto"><code>public class MyPlugin implements Interceptor {
    @Override
    public Object intercept(Invocation invocation) throws Throwable {
        long startTime = System.currentTimeMillis();
        Object result = invocation.proceed();  // 执行目标方法
        long endTime = System.currentTimeMillis();
        System.out.println("SQL执行时间：" + (endTime - startTime) + "ms");
        return result;
    }

    @Override
    public Object plugin(Object target) {
        if (target instanceof Executor) {
            return Plugin.wrap(target, this);  // 为Executor生成代理
        }
        return target;
    }

    @Override
    public void setProperties(Properties properties) {
        // 设置插件属性（如果有）
    }
}</code></pre>
            </div>
            
            <div class="grid md:grid-cols-3 gap-6">
                <div class="bg-white p-6 rounded-xl shadow-md border border-gray-100 card transition-all duration-300">
                    <div class="text-green-500 mb-3 text-2xl">
                        <i class="fas fa-stopwatch"></i>
                    </div>
                    <h3 class="font-bold text-lg mb-2">性能监控</h3>
                    <p class="text-gray-600">记录SQL执行时间，帮助发现性能瓶颈。</p>
                </div>
                <div class="bg-white p-6 rounded-xl shadow-md border border-gray-100 card transition-all duration-300">
                    <div class="text-blue-500 mb-3 text-2xl">
                        <i class="fas fa-filter"></i>
                    </div>
                    <h3 class="font-bold text-lg mb-2">目标过滤</h3>
                    <p class="text-gray-600">通过plugin方法只对Executor实例进行拦截。</p>
                </div>
                <div class="bg-white p-6 rounded-xl shadow-md border border-gray-100 card transition-all duration-300">
                    <div class="text-purple-500 mb-3 text-2xl">
                        <i class="fas fa-layer-group"></i>
                    </div>
                    <h3 class="font-bold text-lg mb-2">无侵入性</h3>
                    <p class="text-gray-600">不改动原有代码，通过代理实现功能增强。</p>
                </div>
            </div>
        </section>

        <!-- Section 6 -->
        <section class="mb-16">
            <h2 class="text-3xl font-bold mb-6 flex items-center">
                <span class="bg-indigo-100 text-indigo-800 w-10 h-10 rounded-full flex items-center justify-center mr-4">6</span>
                <span>插件链与多个插件的支持</span>
            </h2>
            
            <div class="flex flex-col md:flex-row gap-6 mb-8">
                <div class="flex-1">
                    <div class="code-block rounded-lg overflow-hidden">
                        <div class="flex items-center px-4 py-2 bg-gray-700 text-gray-200">
                            <div class="flex space-x-2 mr-4">
                                <span class="w-3 h-3 rounded-full bg-red-500"></span>
                                <span class="w-3 h-3 rounded-full bg-yellow-500"></span>
                                <span class="w-3 h-3 rounded-full bg-green-500"></span>
                            </div>
                            <span class="text-sm">DefaultExecutor.java</span>
                        </div>
                        <pre class="p-4 text-gray-100 overflow-x-auto"><code>public class DefaultExecutor implements Executor {
    private final List&lt;Interceptor&gt; interceptors;

    public Object update(MappedStatement ms, Object parameter) {
        Invocation invocation = new Invocation(this, updateMethod, 
            new Object[]{ms, parameter});
            
        for (Interceptor interceptor : interceptors) {
            invocation = interceptor.plugin(invocation); // 插件链式处理
        }
        return invocation.proceed();  // 执行目标方法
    }
}</code></pre>
                    </div>
                </div>
                <div class="flex-1">
                    <div class="bg-white p-6 rounded-xl shadow-md border border-gray-100 h-full">
                        <div class="flex items-center mb-4">
                            <div class="bg-purple-100 text-purple-800 p-3 rounded-lg mr-4">
                                <i class="fas fa-link text-xl"></i>
                            </div>
                            <div>
                                <h3 class="font-bold text-lg">插件链执行流程</h3>
                            </div>
                        </div>
                        <ul class="space-y-3 text-gray-600">
                            <li class="flex items-start">
                                <i class="fas fa-arrow-right text-purple-500 mt-1 mr-2"></i>
                                <span>MyBatis按照插件注册顺序依次执行</span>
                            </li>
                            <li class="flex items-start">
                                <i class="fas fa-arrow-right text-purple-500 mt-1 mr-2"></i>
                                <span>每个插件可以选择是否继续执行链中的下一个插件</span>
                            </li>
                            <li class="flex items-start">
                                <i class="fas fa-arrow-right text-purple-500 mt-1 mr-2"></i>
                                <span>最终调用原始目标方法</span>
                            </li>
                        </ul>
                    </div>
                </div>
            </div>
            
            <div class="mermaid mb-8">
                graph LR
                    A[客户端调用] --> B[插件1]
                    B --> C[插件2]
                    C --> D[...]
                    D --> E[插件N]
                    E --> F[目标方法]
                    F --> E
                    E --> D
                    D --> C
                    C --> B
                    B --> A
            </div>
        </section>

        <!-- Section 7 -->
        <section class="mb-16">
            <h2 class="text-3xl font-bold mb-6 flex items-center">
                <span class="bg-indigo-100 text-indigo-800 w-10 h-10 rounded-full flex items-center justify-center mr-4">7</span>
                <span>插件与MyBatis核心组件的集成</span>
            </h2>
            
            <div class="bg-white p-6 rounded-xl shadow-md border border-gray-100 mb-8">
                <div class="mermaid">
                    pie
                        title 可拦截的核心组件
                        "Executor" : 35
                        "StatementHandler" : 25
                        "ParameterHandler" : 20
                        "ResultSetHandler" : 20
                </div>
            </div>
            
            <div class="code-block rounded-lg overflow-hidden">
                <div class="flex items-center px-4 py-2 bg-gray-700 text-gray-200">
                    <div class="flex space-x-2 mr-4">
                        <span class="w-3 h-3 rounded-full bg-red-500"></span>
                        <span class="w-3 h-3 rounded-full bg-yellow-500"></span>
                        <span class="w-3 h-3 rounded-full bg-green-500"></span>
                    </div>
                    <span class="text-sm">ExecutorPlugin.java</span>
                </div>
                <pre class="p-4 text-gray-100 overflow-x-auto"><code>public class ExecutorPlugin implements Interceptor {
    @Override
    public Object intercept(Invocation invocation) throws Throwable {
        // 插件逻辑：记录SQL执行前后的日志
        if ("update".equals(invocation.getMethod().getName())) {
            System.out.println("SQL执行开始...");
        }
        Object result = invocation.proceed();
        if ("update".equals(invocation.getMethod().getName())) {
            System.out.println("SQL执行结束...");
        }
        return result;
    }

    @Override
    public Object plugin(Object target) {
        return Plugin.wrap(target, this);
    }

    @Override
    public void setProperties(Properties properties) {
        // 设置插件的配置参数
    }
}</code></pre>
            </div>
        </section>

        <!-- Section 8 -->
        <section class="mb-16">
            <h2 class="text-3xl font-bold mb-6 flex items-center">
                <span class="bg-indigo-100 text-indigo-800 w-10 h-10 rounded-full flex items-center justify-center mr-4">8</span>
                <span>插件的性能与最佳实践</span>
            </h2>
            
            <div class="grid md:grid-cols-3 gap-6 mb-8">
                <div class="bg-white p-6 rounded-xl shadow-md border border-gray-100 card transition-all duration-300">
                    <div class="text-red-500 mb-3 text-2xl">
                        <i class="fas fa-exclamation-triangle"></i>
                    </div>
                    <h3 class="font-bold text-lg mb-2">避免复杂逻辑</h3>
                    <p class="text-gray-600">插件的执行会影响整个SQL执行流程，避免在插件中执行过于复杂的逻辑。</p>
                </div>
                <div class="bg-white p-6 rounded-xl shadow-md border border-gray-100 card transition-all duration-300">
                    <div class="text-yellow-500 mb-3 text-2xl">
                        <i class="fas fa-layer-group"></i>
                    </div>
                    <h3 class="font-bold text-lg mb-2">减少插件链</h3>
                    <p class="text-gray-600">过多的插件会增加SQL执行的延迟，应尽量减少不必要的插件。</p>
                </div>
                <div class="bg-white p-6 rounded-xl shadow-md border border-gray-100 card transition-all duration-300">
                    <div class="text-green-500 mb-3 text-2xl">
                        <i class="fas fa-database"></i>
                    </div>
                    <h3 class="font-bold text-lg mb-2">合理使用缓存</h3>
                    <p class="text-gray-600">在插件中使用缓存可以减少重复操作，提高性能。</p>
                </div>
            </div>
            
            <div class="bg-white p-6 rounded-xl shadow-md border border-gray-100">
                <h3 class="font-bold text-lg mb-4 text-indigo-700">其他最佳实践</h3>
                <ul class="space-y-3 text-gray-600">
                    <li class="flex items-start">
                        <i class="fas fa-check-circle text-indigo-500 mt-1 mr-2"></i>
                        <span>尽量缩小拦截范围，只拦截必要的方法</span>
                    </li>
                    <li class="flex items-start">
                        <i class="fas fa-check-circle text-indigo-500 mt-1 mr-2"></i>
                        <span>避免在插件中抛出异常，以免影响正常业务流程</span>
                    </li>
                    <li class="flex items-start">
                        <i class="fas fa-check-circle text-indigo-500 mt-1 mr-2"></i>
                        <span>考虑插件执行的性能开销，进行必要的性能测试</span>
                    </li>
                    <li class="flex items-start">
                        <i class="fas fa-check-circle text-indigo-500 mt-1 mr-2"></i>
                        <span>为插件提供清晰的配置选项，增强灵活性</span>
                    </li>
                </ul>
            </div>
        </section>
    </div>

    <!-- Footer -->
    <footer class="bg-gray-900 text-gray-300 py-12">
        <div class="container mx-auto max-w-5xl px-4 md:px-0">
            <div class="flex flex-col items-center text-center">
                <h3 class="text-xl font-medium text-white mb-4">技术小馆</h3>
                <a href="http://www.yuque.com/jtostring" class="text-gray-400 hover:text-white transition-colors">
                    <i class="fas fa-external-link-alt mr-2"></i>http://www.yuque.com/jtostring
                </a>
                <div class="mt-6 flex space-x-4">
                    <a href="#" class="text-gray-400 hover:text-white text-xl">
                        <i class="fab fa-github"></i>
                    </a>
                    <a href="#" class="text-gray-400 hover:text-white text-xl">
                        <i class="fab fa-twitter"></i>
                    </a>
                    <a href="#" class="text-gray-400 hover:text-white text-xl">
                        <i class="fab fa-weixin"></i>
                    </a>
                </div>
            </div>
        </div>
    </footer>

    <script>
        mermaid.initialize({
            startOnLoad: true,
            theme: 'default',
            flowchart: { 
                useMaxWidth: false,
                htmlLabels: true
            }
        });
        
        // 平滑滚动
        document.querySelectorAll('a[href^="#"]').forEach(anchor => {
            anchor.addEventListener('click', function (e) {
                e.preventDefault();
                document.querySelector(this.getAttribute('href')).scrollIntoView({
                    behavior: 'smooth'
                });
            });
        });
    </script>
</body>
</html>
```